package zhihui.mobile.wxapi;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import zhihui.mobile.app.MyApplication;
import zhihui.mobile.config.Config;
import zhihui.mobile.ui.utils.UiUtils;

/**
 * Created by 张公铭 on 2017/9/14 0014.
 */

public class WXEntryActivity extends AppCompatActivity  implements IWXAPIEventHandler
{
    private IWXAPI api;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        api = WXAPIFactory.createWXAPI(this, Config.WX_APP_ID);
        api.registerApp(Config.WX_APP_ID);
        api.handleIntent(getIntent(), this);
    }

    @Override
    public void onReq(BaseReq baseReq)
    {

    }

    @Override
    public void onResp(BaseResp baseResp)
    {
        switch (baseResp.errCode) {
            case BaseResp.ErrCode.ERR_OK:
                com.zgm.utils.UiUtils.ToastInCenter(this, "分享成功！", Toast.LENGTH_SHORT);
                MyApplication.finishActivity(WXEntryActivity.class);
                break;
            case BaseResp.ErrCode.ERR_USER_CANCEL:
                com.zgm.utils.UiUtils.ToastInCenter(this, "分享取消！", Toast.LENGTH_SHORT);
                MyApplication.finishActivity(WXEntryActivity.class);
                break;
            case BaseResp.ErrCode.ERR_AUTH_DENIED:
                com.zgm.utils.UiUtils.ToastInCenter(this, "分享被拒绝！", Toast.LENGTH_SHORT);
                MyApplication.finishActivity(WXEntryActivity.class);
                break;
            default:
                com.zgm.utils.UiUtils.ToastInCenter(this, "分享失败！", Toast.LENGTH_SHORT);
                MyApplication.finishActivity(WXEntryActivity.class);
                break;
        }
    }
}
